class Admins::NewMediaController < ApplicationController
  before_action :set_new_medium, only: [:show, :edit, :update, :destroy]

  # GET /new_media
  # GET /new_media.json
  def index
    @new_media = NewMedium.order("postion_num asc") 
  end

  # GET /new_media/1
  # GET /new_media/1.json
  def show
  end

  # GET /new_media/new
  def new
    @new_medium = NewMedium.new
  end

  # GET /new_media/1/edit
  def edit
  end

  # POST /new_media
  # POST /new_media.json
  def create
    @new_medium = NewMedium.new(new_medium_params)

    respond_to do |format|
      if @new_medium.save
        format.html { redirect_to admins_new_media_url, notice: 'New medium was successfully created.' }
        format.json { render :show, status: :created, location: @new_medium }
      else
        format.html { render :new }
        format.json { render json: @new_medium.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /new_media/1
  # PATCH/PUT /new_media/1.json
  def update
    respond_to do |format|
      if @new_medium.update(new_medium_params)
        format.html { redirect_to admins_new_media_url, notice: 'New medium was successfully updated.' }
        format.json { render :show, status: :ok, location: @new_medium }
      else
        format.html { render :edit }
        format.json { render json: @new_medium.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /new_media/1
  # DELETE /new_media/1.json
  def destroy
    @new_medium.destroy
    respond_to do |format|
      format.html { redirect_to admins_new_media_url, notice: 'New medium was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_new_medium
      @new_medium = NewMedium.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def new_medium_params
      params.require(:new_medium).permit(:name, :link_url, :mouse_on_image, :mouse_off_image, :postion_num)
    end
end
